<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, height=device-height, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
    <title>Vod</title>
    <link rel="stylesheet" href="https://g.alicdn.com/de/prismplayer/2.6.0/skins/default/aliplayer-min.css"/>
    <script src="lib/es6-promise.min.js"></script>
    <script src="lib/aliyun-oss-sdk-5.2.0.min.js"></script>
    <script src="js/aliyun-upload-sdk-1.4.0.min.js"></script>
</head>
<body>


<form action="">
    <input type="file" name="file" id="files" multiple />
</form>

<button id="b1" onclick="f()">开始上传</button>
<script>
    var uploader = new AliyunUpload.Vod({
        //分片大小默认1M，不能小于100K
        partSize: 1048576,
        //并行上传分片个数，默认5
        parallel: 5,
        //网络原因失败时，重新上传次数，默认为3
        retryCount: 3,
        //网络原因失败时，重新上传间隔时间，默认为2秒
        retryDuration: 2,
        // 开始上传
        'onUploadstarted': function (uploadInfo) {
            console.log(uploadInfo.videoId+"onUploadStarted:" + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
            //上传方式1, 需要根据uploadInfo.videoId是否有值，调用点播的不同接口获取uploadauth和uploadAddress，如果videoId有值，调用刷新视频上传凭证接口，否则调用创建视频上传凭证接口
            uploader.setUploadAuthAndAddress(uploadInfo,"eyJTZWN1cml0eVRva2VuIjoiQ0FJUzB3UjFxNkZ0NUIyeWZTaklyNG5HUE8zWm1icHcvN0d2VEdQNjFsVTRmZDlWdGZUQzJqejJJSGhKZVhOdkJPMGV0ZjQrbVdCWTdQY1lsclVxRjhZZUd4V2VQWm9xc00wR3IxNzhKcGZadjh1ODRZQURpNUNqUVlFUDRxWmNtSjI4V2Y3d2FmK0FVQkxHQ1RtZDVNQVlvOWJUY1RHbFFDWnVXLy90b0pWN2I5TVJjeENsWkQ1ZGZybC9MUmRqcjhsbzF4R3pVUEcyS1V6U24zYjNCa2hsc1JZZTcyUms4dmFI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JVbXFQeVoxaTgiLCJFeHBpcmVVVENUaW1lIjoiMjAxOC0wOC0wMlQwOTozODoxMloiLCJBY2Nlc3NLZXlTZWNyZXQiOiI1R1BrUmt1YUV6Y3ZEWkJnZ0F6M01KWUNraXBzNFdybWNuWUZVYlZVcmN1dyIsIkV4cGlyYXRpb24iOiIzNjAwIn0=",
                "eyJFbmRwb2ludCI6Imh0dHBzOi8vb3NzLWNuLXNoYW5naGFpLmFsaXl1bmNzLmNvbSIsIkJ1Y2tldCI6Im91dGluLWZjNTU0M2I3OGY0ZDExZThhZGZlMDAxNjNlMWM3NDI2IiwiRmlsZU5hbWUiOiJpbWFnZS9jb3Zlci83QkRDQzNFREZBQUM0NTc2QkMxN0NCMzgwNTc2MTQ3NC02LTIuanBnIn0=",
                "c82f74c2fe0a4969a683db17a1d6d56c");
            //上传方式2
            // uploader.setSTSToken(uploadInfo, accessKeyId, accessKeySecret,secretToken);
        },
        // 文件上传成功
        'onUploadSucceed': function (uploadInfo) {
            console.log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
        },
        // 文件上传失败
        'onUploadFailed': function (uploadInfo, code, message) {
            console.log("onUploadFailed: file:" + uploadInfo.file.name + ",code:" + code + ", message:" + message);
        },
        // 文件上传进度，单位：字节
        'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
            console.log("onUploadProgress:file:" + uploadInfo.file.name + ", fileSize:" + totalSize + ", percent:" + Math.ceil(loadedPercent * 100) + "%");
        },
        // 上传凭证超时
        'onUploadTokenExpired': function (uploadInfo) {
            console.log("onUploadTokenExpired");
            //上传方式1  实现时，根据uploadInfo.videoId调用刷新视频上传凭证接口重新获取UploadAuth
            // uploader.resumeUploadWithAuth(uploadAuth);
            // 上传方式2 实现时，从新获取STS临时账号用于恢复上传
            // uploader.resumeUploadWithSTSToken(accessKeyId, accessKeySecret, secretToken, expireTime);
        },
        //全部文件上传结束
        'onUploadEnd':function(uploadInfo){
            console.log("onUploadEnd: uploaded all the files");
        }
    });
    var userData = '{"Vod":{"UserData":"{"IsShowWaterMark":"false","Priority":"7"}"}}';

    document.getElementById("files")
        .addEventListener('change', function (event) {
            console.log("绑定");
            for(var i=0; i<event.target.files.length; i++) {
                console.log("tianjia ");
                console.log(event.target.files[i].length);
                uploader.addFile(event.target.files[i], null, null, null, null);
            }
        });


    function f() {
        console.log("开始上传");
        uploader.startUpload();
    }
</script>
</body>
</html>